<template>
    <section>
        <sy-baselist
                :filters="filters"
                listUrl="server/business/Daily.ashx?cmd=GetSearchList"
                hideAdd
                hideOperate
                @beforeSearch="beforeSearch"
                @onLoadRow="onLoadRow"
                :autoSearch="false"
                hidePagination
        >
            <el-table-column
                    prop="FSubitemName"
                    label="单项工程"
                    width="280">
            </el-table-column>
            <el-table-column
                    v-for="(item,index) in columnslist"
                    :prop="'FItem'+(index+1)"
                    :label="item.FName"
                    width="120">
            </el-table-column>
            <template  slot="extendbtnTop">
            <el-button type="success" size="small"  :loading="excelLoading"  @click="exportExcel()">导出Excel</el-button>
            </template>
        </sy-baselist>

    </section>
</template>

<script>
    import util from '../../common/util'
    export default {
        data(){
            return {
                filters: [{type: "date",name:"FDate",text:"时间", value: null},
                    {type: "select",name:"FProjectID",text:"工程",valueKey:"FID",remote:true,
                        data:"server/setting/Project.ashx?cmd=GetOptions"
                    }],
                columnslist:[]
            }
        },
        methods:{
            beforeSearch(para,r){
                let projectID = 0
                this.columnslist=[]
                if (this.filters[1].value) {
                    projectID = this.filters[1].value
                    util.get("server/business/Single.ashx?cmd=GetList",
                        {where: "FProjectID=" + projectID, start: "0", limit: '10'}, this.switchLoading, result => {
                            this.columnslist = result.data
                        })
                } else {
                    r.error="请选择工程";
                }
            },
            onLoadRow(row){
                row.FSubitemID = row[0]
                row.FSubitemName = row[1]
                row.FItem1 = row[2]
                row.FItem2 = row[3]
                row.FItem3 = row[4]
                row.FItem4 = row[5]
                row.FItem5 = row[6]
                row.FItem6 = row[7]
                row.FItem7 = row[8]
                row.FItem8 = row[9]
                row.FItem9 = row[10]
                row.FItem10= row[11]
            },
            exportExcel(){
               let startdate =''
               let enddate=''
               let projectID = 0
                if (this.filters[1].value) {
                    projectID = this.filters[1].value
                }
                else{
                    util.msgWarning("请选择工程")
                    return;
                }
                if (this.filters[0].value){
                    startdate = util.date.format(this.filters[0].value[0],'yyyy-MM-dd')
                    enddate = util.date.format(this.filters[0].value[1],'yyyy-MM-dd')
                }
                window.open(global.serverHost + "server/business/Daily.ashx?cmd=ExportExcel&ProjectID="
                    +projectID+"&startdate="+startdate+"&endate="+enddate);
            }
        },
        created(){

        }
    }
</script>